package io.wongxd.demo.page.views

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.wongxd.demo.M
import io.wongxd.demo.resourcePainter
import io.wongxd.solution.baseView.BaseComposeToolBarFgt
import io.wongxd.solution.compose.custom.views.menu_fab.MenuFabItem
import io.wongxd.solution.compose.custom.views.menu_fab.MenuFloatingActionButton
import io.wongxd.solution.compose.custom.views.other.FpsText

class FgtViewMenuFab : BaseComposeToolBarFgt() {
    override fun lazyInit() {

    }

    override val title: String
        get() = "FgtViewMenuFab 带菜单的Fab"

    @Composable
    override fun Render() {
        ComposeContent()
    }

    private val menuItems = ArrayList<MenuFabItem>().apply {
        add(
            MenuFabItem(
                icon = {
                    Icon(
                        modifier = Modifier.size(16.dp),
                        painter = resourcePainter("ic_empty_delete"),
                        contentDescription = "",
                        tint = Color.White
                    )
                },
                "删除"
            )
        )
        add(
            MenuFabItem(
                icon = {
                    Icon(
                        modifier = Modifier.size(16.dp),
                        painter = resourcePainter("ic_empty_update"),
                        contentDescription = "",
                        tint = Color.White
                    )
                },
                "更新"
            )
        )
    }


    @Composable
    private fun ComposeContent() {
        FpsText(modifier = M)
        Box(M.fillMaxSize()) {
            MenuFloatingActionButton(
                srcIcon = Icons.Filled.Add,
                items = menuItems,
                modifier = Modifier
                    .align(Alignment.BottomEnd)
                    .padding(bottom = 30.dp),
            ) {
                "点击了${it.label}".showToast()
            }
        }
    }

    @Preview(showBackground = true, backgroundColor = 0xffffffff)
    @Composable
    fun RenderPreView() {

    }
}